package cn.luoyifan.feign.clients;

import cn.luoyifan.domain.User;
import feign.hystrix.FallbackFactory;

//降级类都要去实现一个：FallbackFactory的接口：泛型
public class UserFeignClientFallbackFactory implements FallbackFactory<UserFeignClient> {

    //Throwable:异常
    @Override
    public UserFeignClient create(Throwable throwable) {
        return new UserFeignClient(){
            // 用匿名内部类去复写一个方法
            @Override
            public User getById(Long id) {
                //打印异常
                throwable.printStackTrace();
                //这个就是降级方法
                return new User(-1L,"","用户服务不可用，用户获取失败");
            }
        };
    }
}
